package com.jinxin.platform.cdsmsmgr.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jinxin.platform.cdsmsmgr.pojo.domains.SmsTemplateInfo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author 那个男人
 * @Date 2022/12/30 17:18
 * @Version 1.0
 */
public class Test2 {
    public static void main(String[] args) {
        SmsTemplateInfo t1 = new SmsTemplateInfo();
        t1.setCode("123");
        SmsTemplateInfo t2 = new SmsTemplateInfo();
        t2.setCode("456");
        List<SmsTemplateInfo> list =new ArrayList<>();
        list.add(t1);
        list.add(t2);

        Long[] templateIdSet = list.stream()
                .map(template -> Long.parseLong(template.getCode()))
                .toArray(Long[]::new);
        System.out.println(Arrays.toString(templateIdSet));


        String str = "fegdggs，{10} gdgd{gh}";
        System.out.println(Utils.isVerfifyCodeTemplate(str));
        System.out.println(DateUtil.getTimeStrBySeconds(1673256098));


//        Pattern p = Pattern.compile("\\{([1-9][0-9]*)}");
        Pattern p = Pattern.compile("\\$\\{(.*?)}");
        String templateContent = "尊敬的财停车会员您好,您在${place}的包时停车时间将于${time}到期，请及时缴费延长包时时间!";
        Matcher matcher = p.matcher(templateContent);
        int count=0;   //匹配的数量
        int index =0;
        List<String> paramList = new ArrayList<>();
        paramList.add("车场1");
        paramList.add("2023年12月31日");
        int size = paramList.size();
        String sendContent = templateContent;
        String[] paramArr = new String[size];

        while (matcher.find()){
            count++;
            if(count > size){
                System.out.println("模板实际值与变量的个数不匹配");
                break;
            }
            String group = matcher.group();
            sendContent = sendContent.replace(group,paramList.get(index));
            paramArr[index] = matcher.group();
            index++;
        }
        System.out.println("发送内容: " + sendContent);
        String[] strings = paramList.toArray(new String[0]);
        System.out.println(Arrays.toString(strings));

        System.out.println("====================");
        String s1 = "ad";
        String s2 = "134334";
        JSONArray templateParamJsonArr = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","张三");
        jsonObject1.put("code","123");
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","王麻子");
        jsonObject2.put("code","456");
        templateParamJsonArr.add(jsonObject1);
        templateParamJsonArr.add(jsonObject2);
        System.out.println(templateParamJsonArr.toJSONString());
        String phone1 = "15928085495";
        String phone2 = "19302849238";
        String ss = "[\""+phone1+"\",\""+phone2+"\"]";
        System.out.println(ss);
    }
}
